package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.StrategyDetail;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCatalogQueryObject;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("strategyDetail")
public class StrategyDetailController {
    @Autowired
    private IStrategyDetailService detailService;
       @Autowired
    private IStrategyService strategyService;

    @RequestMapping("list")
    public String list(@ModelAttribute("qo")QueryObject qo, Model model){
        model.addAttribute("pageInfo",detailService.query(qo));
        model.addAttribute("strategies",strategyService.listAll());
        return "strategy/detail";
    }
    @RequestMapping("saveOrUpdate")
    public String saveOrUpdate(StrategyDetail detail, MultipartFile file){
        if (file != null && file.getSize() >0){
            String path = UploadUtil.upload(file, UploadUtil.PATH + "/upload");
            detail.setCoverUrl(path);
        }
        detailService.saveOrUpdate(detail);
        return "redirect:/strategyDetail/list.do";
    }

}
